package com.cgnpc.scp.hse.controller;

import com.cgnpc.cud.annotation.OperatorType;
import com.cgnpc.cud.annotation.UBA;
import com.cgnpc.cud.core.domain.AjaxResult;
import com.cgnpc.framework.userinfo.CurrentUser;
import com.cgnpc.scp.common.pojo.UserInfo;
import com.cgnpc.scp.common.utils.AjaxResultUtil;
import com.cgnpc.scp.hse.mybatis.entity.HseMeetingUser;
import com.cgnpc.scp.hse.service.IHseMeetingUserService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.support.RequestContextUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.Locale;

/******************************
 * 用途说明: 调试HSE管理-会议信息-参会人员
 * 作者姓名: yblrs
 * 创建时间: 2020/8/20 21:26
 ******************************/
@Controller
@RequestMapping("/scp/hse/meetingUser")
public class HseMeetingUserController {
    private static final Logger LOGGER = LoggerFactory.getLogger(HseMeetingUserController.class);

    @Autowired
    private CurrentUser currentUser;

    @Autowired
    private IHseMeetingUserService hseMeetingUserService;

    /**********************************
     * 用途说明: 调试HSE管理-会议信息-参会人员---签到
     * 参数说明: HttpServletRequest request, @RequestBody T reqEntity
     * 返回值说明: Object
     ***********************************/
    @ApiOperation(value = "调试HSE管理-会议信息-参会人员---签到")
    @UBA(module = "调试HSE管理", action = "参会人员签到", channel = OperatorType.Button)
    @RequestMapping(value = "/signIn", method = {RequestMethod.POST})
    @ResponseBody
    public <T extends HseMeetingUser> Object signIn(HttpServletRequest request, @RequestBody T reqEntity) {
        AjaxResult ajaxResult = null;

        try {
            // 获取当前的登录用户信息
            UserInfo loginUserInfo = currentUser.getCurrentUserDetail();
            // 获取请求的语言reqLocale，cookie需要包含lang=cn，或者lang=en
            Locale reqLocale = RequestContextUtils.getLocaleResolver(request).resolveLocale(request);

            ajaxResult = hseMeetingUserService.signIn(loginUserInfo, reqLocale, reqEntity);
        } catch (Exception e) {
            LOGGER.error("signIn.error;", e);
            ajaxResult = AjaxResultUtil.createErrorMessage();
        }

        return ajaxResult;
    }

}
